--USE [ClinicalStudyBase]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ScheduleSubjectVisit_Subject]') AND parent_object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]'))
ALTER TABLE [dbo].[ScheduleSubjectVisit] DROP CONSTRAINT [FK_ScheduleSubjectVisit_Subject]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ScheduleSubjectVisit_Visit]') AND parent_object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]'))
ALTER TABLE [dbo].[ScheduleSubjectVisit] DROP CONSTRAINT [FK_ScheduleSubjectVisit_Visit]
GO

--USE [ClinicalStudyBase]
GO

/****** Object:  Table [dbo].[ScheduleSubjectVisit]    Script Date: 08/16/2011 23:19:34 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]') AND type in (N'U'))
DROP TABLE [dbo].[ScheduleSubjectVisit]
GO

--USE [ClinicalStudyBase]
GO

/****** Object:  Table [dbo].[ScheduleSubjectVisit]    Script Date: 08/16/2011 23:19:34 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ScheduleSubjectVisit](
	[SubjectId] [int] NOT NULL,
	[VisitId] [int] NOT NULL,
 CONSTRAINT [PK_ScheduleSubjectVisit] PRIMARY KEY CLUSTERED 
(
	[SubjectId] ASC,
	[VisitId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ScheduleSubjectVisit_Subject]') AND parent_object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]'))
ALTER TABLE [dbo].[ScheduleSubjectVisit]  WITH CHECK ADD  CONSTRAINT [FK_ScheduleSubjectVisit_Subject] FOREIGN KEY([SubjectId])
REFERENCES [dbo].[Subject] ([SubjectId])
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ScheduleSubjectVisit_Subject]') AND parent_object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]'))
ALTER TABLE [dbo].[ScheduleSubjectVisit] CHECK CONSTRAINT [FK_ScheduleSubjectVisit_Subject]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ScheduleSubjectVisit_Visit]') AND parent_object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]'))
ALTER TABLE [dbo].[ScheduleSubjectVisit]  WITH CHECK ADD  CONSTRAINT [FK_ScheduleSubjectVisit_Visit] FOREIGN KEY([VisitId])
REFERENCES [dbo].[Visit] ([VisitId])
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ScheduleSubjectVisit_Visit]') AND parent_object_id = OBJECT_ID(N'[dbo].[ScheduleSubjectVisit]'))
ALTER TABLE [dbo].[ScheduleSubjectVisit] CHECK CONSTRAINT [FK_ScheduleSubjectVisit_Visit]
GO


